//package com.dirox.plugins.ao;
//
//import com.atlassian.sal.api.user.UserManager;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.text.DateFormat;
//
//import static com.google.common.base.Preconditions.*;
//
//public final class NoteServlet extends HttpServlet
//{
//	private final NoteService noteService;
//	private final UserManager userManager;
//
//	public NoteServlet(NoteService noteService, UserManager userManager)
//	{
//		this.noteService = checkNotNull(noteService);
//		this.userManager = checkNotNull(userManager);
//	}
//
//	@Override
//	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
//	{
//		enforceLoggedIn(req, res);
//
//		final PrintWriter w = res.getWriter();
//		w.printf("<h1>Notes (%s)</h1>", userManager.getRemoteUsername());
//
//		// the form to post more TODOs
//		w.write("<form method=\"post\">");
//		w.write("ID: <input type=\"text\" name=\"id\" size=\"25\"/>");
//		w.write("<br/>");
//		w.write("Content: <input type=\"text\" name=\"content\" size=\"25\"/>");
//		w.write("<br/>");
//		w.write("Priority: <input type=\"text\" name=\"priority\" size=\"25\"/>");
//		w.write("<br/>");
//		w.write("Status: <input type=\"text\" name=\"status\" size=\"25\"/>");
//		w.write("<br/>");
//		w.write("<input type=\"submit\" name=\"submit\" value=\"Add\"/>");
//		w.write("</form>");
//
//		w.write("<ol>");
//
//		for (Note note : noteService.getAll())
//		{
//			w.printf("<li><%2$s> %s </%2$s></li>", note.getContent(), note.getStatus() ? "strike" : "strong");
//			w.printf("ID: %s ", String.valueOf(note.getID()));
//			w.printf("priority: %s ", (note.getPriority() != null) ? note.getPriority().toString() : "0");
//			w.printf("owner: %s ", (note.getUser() != null) ? note.getUser().getName() : "null");
//			w.printf("owner_ID: %s ", note.getUser().getID());
//			w.printf("createdDate: %s ", DateFormat.getInstance().format(note.getCreatedDate()));
//			
//		}
//
//		w.write("</ol>");
//		w.write("<script language='javascript'>document.forms[0].elements[0].focus();</script>");
//
//		w.close();
//	}
//
//	@Override
//	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
//	{
//		enforceLoggedIn(req, res);
//
//		final Integer id = req.getParameter("id").isEmpty() ? 0 : Integer.valueOf(req.getParameter("id"));
//		final String content = req.getParameter("content");
//		final Integer priority = Integer.valueOf(req.getParameter("priority"));
//		final boolean status = Integer.valueOf(req.getParameter("status")) == 0 ? true : false;
//		if (id == 0) {
//			noteService.add(content, priority,status);
//		} else {
//			noteService.update(id, content, priority,status);
//		}
//		res.sendRedirect(req.getContextPath() + "/plugins/servlet/note/list");
//	}
//
//	private void enforceLoggedIn(HttpServletRequest req, HttpServletResponse res) throws IOException
//	{
//		if (userManager.getRemoteUsername() == null)
//		{
//			res.sendRedirect(req.getContextPath() + "/plugins/servlet/login");
//		}
//	}
//}
